package cn.johnyu.service.impl;

import cn.johnyu.repository.AccountRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.ReactiveUserDetailsService;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;

@Service
public class MongoDetailsService implements ReactiveUserDetailsService {
    @Autowired
    private AccountRepository accountRepository;
    @Override
    public Mono<UserDetails> findByUsername(String username) {
        //因为ReactiveUserDetailsService接口的方法返回类型设计的不完善（更好是：Mono<? extends UserDetails>)
        //所以需要进行一次map操作
        return accountRepository.findAccountByUsername(username).map(account->account);
    }
}
